<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Userlist_Model extends CI_Model
{
    public function checkLogin()
    {
        $user = $this->session->userdata('user');
        return isset($user['isUser']) && $user['isUser'];
    }

    public function login($data)
    {
        $query = $this->db->get_where('G_Sys_UserList', 
                array('UserName'=>$data['UserName'], 'PWD'=>$data['PWD']),
                1);

        $users = $query->result();
        $user = empty($users) ? false : $users[0];
        
        //用户是否存在，如果存在则写入session
        if($user)
        {		
            $array = array(
                'user'=>array(
                'UserName'=>$user->UserName,
                'RecID'=>$user->RecID,
                'isUser'=>true,
            ));

            $this->session->set_userdata($array);
            
            
                return true;
        }
        else
            return false;
    }
    
    public function logout()
    {
        return $this->session->unset_userdata('user');
    }
}
